package com.ybkj.daijia.server.service.impl;

import com.ybkj.daijia.DateTimeUtils;
import com.ybkj.daijia.Setting;
import com.ybkj.daijia.serverUtils.IOUtils;
import com.ybkj.daijia.serverUtils.SettingUtils;
import com.ybkj.daijia.api.util.ImageUtil;
import com.ybkj.daijia.server.amqp.rabbitTemplate.PushTemplate;
import com.ybkj.daijia.server.mapper.CompanyMapper;
import com.ybkj.daijia.server.mapper.DriverMapper;
import com.ybkj.daijia.server.mapper.PeccancyAndComplainMapper;
import com.ybkj.daijia.server.mapper.PlatformSettingMapper;
import com.ybkj.daijia.server.mc.Passenger;
import com.ybkj.daijia.server.model.Area;
import com.ybkj.daijia.server.model.Company;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.model.FeeScale;
import com.ybkj.daijia.server.model.PeccancyAndComplain;
import com.ybkj.daijia.server.model.SettleAccountsCycle;
import com.ybkj.daijia.server.model.Train;
import com.ybkj.daijia.server.service.AreaService;
import com.ybkj.daijia.server.service.DriverTimeService;
import com.ybkj.daijia.server.service.FeeScaleService;
import com.ybkj.daijia.server.service.MemberService;
import com.ybkj.daijia.server.service.SuperviceService;
import com.ybkj.daijia.server.service.ZhuancheService;
import com.ybkj.daijia.server.sp.CfxxMessage;
import com.ybkj.daijia.server.sp.CkbaMessage;
import com.ybkj.daijia.server.sp.CkblMessage;
import com.ybkj.daijia.server.sp.CkpjMessage;
import com.ybkj.daijia.server.sp.ClbaMessage;
import com.ybkj.daijia.server.sp.ClbxMessage;
import com.ybkj.daijia.server.sp.DcyyMessage;
import com.ybkj.daijia.server.sp.DdbcMessage;
import com.ybkj.daijia.server.sp.DdcxMessage;
import com.ybkj.daijia.server.sp.DdjsMessage;
import com.ybkj.daijia.server.sp.DdpdMessage;
import com.ybkj.daijia.server.sp.JgxxMessage;
import com.ybkj.daijia.server.sp.JszqMessage;
import com.ybkj.daijia.server.sp.ShenZhenTimer;
import com.ybkj.daijia.server.sp.SjbaMessage;
import com.ybkj.daijia.server.sp.SjpxMessage;
import com.ybkj.daijia.server.sp.SjwzMessage;
import com.ybkj.daijia.server.sp.SjxxMessage;
import com.ybkj.daijia.server.sp.TjyyMessage;
import com.ybkj.daijia.server.sp.YjxxMessage;
import com.ybkj.daijia.server.zhuan.Car;
import com.ybkj.daijia.server.zhuan.Order;
import com.ybkj.daijia.server.zhuan.Order.ServiceType;
import com.ybkj.daijia.server.zhuan.OrderStatus;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Shine
 */
@Service
public class DefaultSuperviceService implements SuperviceService {

    @Autowired
    private PushTemplate pushTemplate;

    @Autowired
    private SettingUtils settingUtils;

    @Autowired
    private AreaService areaService;

    @Autowired
    private ZhuancheService zhuancheService;

    @Autowired
    private MemberService memberService;

    @Autowired
    private DriverMapper driverMapper;

    @Autowired
    private PeccancyAndComplainMapper peccancyAndComplainMapper;

    @Autowired
    private CompanyMapper companyMapper;

    @Autowired
    private DriverTimeService driverTimeService;

    @Autowired
    private PlatformSettingMapper platformSettingMapper;

    @Autowired
    private FeeScaleService feeScaleService;


    @Override
    public void pushDdcx(Order order, String cancelCause, String who) {
        try {

            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            //
            if (setting.isUpPlatformInfo()) {
                // 封装数据
                DdcxMessage message = new DdcxMessage();
                message.setOrderNo(order.getOrderNo());
                message.setOrderTime(order.getCreated());
                message.setCancelTime(new Date());
                message.setStartLat(order.getStartLat());
                message.setStartLng(order.getStartLng());
                if ("appCancel".equals(who)) { // 司机销单
                    message.setCanceler("2");
                    message.setCancelTypeCode("2");
                } else if ("adminCancel".equals(who)) { // 后台消单
                    message.setCanceler("3");
                    message.setCancelTypeCode("3");
                } else if ("customerCancel".equals(who)) { // 客户销单(微信上)
                    message.setCanceler("1");
                    message.setCancelTypeCode("1");
                }
                message.setCancelReason(cancelCause);
                message.setAddress("0"); // 默认值

                pushTemplate.sendMessage(message);
            }

        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void pushDdjs(Order order) {
        try {

            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                DdjsMessage message = new DdjsMessage();
                message.setOrderNo(order.getOrderNo());
                message.setUseTime(order.getServerTime());
                message.setOrderTime(order.getCreated());
                message.setPassengerDemand(order.getMemo());
                message.setUseLocale(order.getStartAddress());
                message.setUseLat(order.getStartLat());
                message.setUseLon(order.getStartLng());
                message.setDestination(order.getEndAddress());
                message.setDestLat(order.getEndLat());
                message.setDestLon(order.getEndLng());
                message.setEncrypt(3);
                Area area = areaService.findOneWithCharge(order.getAreaId());
                message.setTransPriceType(area.getName());

                Long passengerId = order.getPassengerId();
                Passenger passenger = memberService.findOnePassenger(passengerId);
                message.setPassengerTel(passenger.getPhone());
                message.setPassengerName(passenger.getName());
                pushTemplate.sendMessage(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void pushDdpd(Order order, Driver driver) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                DdpdMessage message = new DdpdMessage();
                message.setOrderNo(order.getOrderNo());
                message.setVehicleLat(driver.getLastLatitude());
                message.setVehicleLon(driver.getLastLongitude());
                message.setEncrypt(3);
                message.setDriverIdCode(driver.getIdCard());
                message.setDriverTel(driver.getPhone());
                message.setVehicleLicense(order.getCarNumber());
                message.setDispatchTime(new Date());
                message.setDriCertNo(driver.getTaxiLicenseNo());
                message.setDriverName(driver.getRealname());
                Long carId = driver.getCarId();
                Car car = zhuancheService.findCar(carId);
                message.setVehCertNo(car.getTaxiNo());
                // 添加驾驶员定位信息
                SjwzMessage sjwzMessage = addSjwzMessage(driver);
                message.setSjwzMessage(sjwzMessage);

                // 上传监管平台
                pushTemplate.sendMessage(message);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }

    }

    @Override
    public void pushDcyy(Order order, Passenger passenger, Driver driver) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                DcyyMessage message = new DcyyMessage();

                order = zhuancheService.findOne(order.getId());
                // 订单号(orderNo)
                message.setOrderNo(order.getOrderNo());
                // 司机姓名(driverName)
                Car car = zhuancheService.findCar(order.getCarId());
                message.setDriverName(driver.getRealname());
                // 网约车驾驶员证号(driverIdCode)
                message.setDriverIdCode(driver.getIdCard());
                // 车牌号码(vehicleLicense)
                message.setVehicleLicense(car.getCarNumber());
                // 车辆实际出发地点经度 (realVehicleLon)
                message.setRealVehicleLon(order.getRealStartLng());// 车辆实际出发地点经度
                // 车辆实际出发地点纬度 (realVehicleLat)
                message.setRealVehicleLat(order.getRealStartLat());// 车辆实际出发地点纬度
                // 完成时车辆经度(destVehLon)
                message.setDestVehLon(order.getEndLng());
                // 完成时车辆纬度(destVehLat)
                message.setDestVehLat(order.getEndLat());
                // 上车时间(onTime)
                List<OrderStatus> statusList = order.getStatusList();
                for (OrderStatus orderStatus : statusList) {
                    if (orderStatus.getStatus() == 4) {
                        message.setOnTime(orderStatus.getCreated());
                    }
                }
                // 下车时间(offTime)
                for (OrderStatus orderStatus : statusList) {
                    if (orderStatus.getStatus() == 5) {
                        message.setOffTime(orderStatus.getCreated());
                        // 结算时间(calTime)
                        message.setCalTime(orderStatus.getCreated());
                    }
                }
                // 实际上车地点 (realOnLocation)
                message.setRealOnLocation(order.getRealStartAddress());// 实际上车地点
                // 实际下车地点 (realOffLocation)
                message.setRealOffLocation(order.getEndAddress());// 实际下车地点
                // 乘客电话(passengerTel)
                message.setPassengerTel(passenger.getPhone());
                // 空驶里程(noneMil)
                message.setNoneMil(0.0);
                // 待客里程（waitMil）
                message.setWaitMil(0.0);
                // 载客里程(passengerMil)
                message.setPassengerMil(order.getMileage());
                // 载客时间(passengerTime)
                message.setPassengerTime(order.getRunTime().doubleValue());
                // 低速时长 (lowSpeedTime)
                message.setLowSpeedTime(0.0);
                // 等候时间(waitingTime)
                message.setWaitingTime(0.0);
                // 现金支付金额(cash)
                message.setCash(order.getCashMoney().doubleValue());
                // 电子支付金额(elePay)
                message.setElePay(
                    order.getAlipayMoney().doubleValue() + order.getWeixinMoney().doubleValue()
                        + order.getSignMoney().doubleValue()
                        + order.getBalanceMoney().doubleValue());
                // Pos机支付金额(posPay)
                message.setPosPay(0.0);
                // 实收金额(paid)
                message.setPaid(order.getRealPay());
                // 应收金额(receivable)
                message.setReceivable(
                    order.getRealPay().doubleValue() + order.getCouponMoney().doubleValue());
                // 优惠金额(bargain)
                message.setBargain(order.getCouponMoney().doubleValue());
                // 电召费/预约服务费(callCharge)
                message.setCallCharge(0.0);
                // 等候费用(waitingCharge)
                message.setWaitingCharge(order.getWaitPrice());
                // 附加费(extraCharge)
                message.setExtraCharge(
                    order.getGuoluMoney().doubleValue() + order.getYuanchengMoney().doubleValue()
                        + order.getYuanchengMoney().doubleValue());
                // 其他附加费用(otherExtraCharge)
                message.setOtherExtraCharge(order.getOtherMoney().doubleValue());
                // 高峰时段时间加价金额(rushAddCharge)
                message.setRushAddCharge(0.0);
                // 夜间时段里程加价金额(nightAddCharge)
                message.setNightAddCharge(0.0);
                // 动态加价金额(dynamicsAddCharge)
                message.setDynamicsAddCharge(0.0);
                // 特殊情况加价倍数（specialTimes）
                message.setSpecialTimes(0.0);
                // 特殊情况加价倍数说明（specialTimesNote）
                message.setSpecialTimesNote("");
                // 司机实收金额（driverIncome）
                message.setDriverIncome(
                    order.getEmployProfit() == null ? 0.00 : order.getEmployProfit());
                // 司机应收金额（driverReceivable）
                message.setDriverReceivable(order.getRealPay() == null ? 0.00 : order.getRealPay());
                // 运价类型 (transPriceType)
                Area area = areaService.findOne(order.getAreaId());
                if (null != area) {
                    message.setTransPriceType(area.getName());
                }
                // Pos机收单机构(posAgency)
                message.setPosAgency("");
                // 电子支付机构(ePay)
                message.setePay("支付宝");
                // 结算状态(calStatus)
                message.setCalStatus("1");
                // 发票状态(billStatus)
                // 订单时间
                message.setOrderTime(order.getCreated());

                /**
                 * 经营出发
                 */
                // 出发4,完成5
                int orderStatus = order.getStatus();
                String yyFlage = (orderStatus == 4 ? "CF" : null);
                message.setYyFlage(yyFlage);
                // message.setOrderNo(order.getOrderNo());
                // message.setDriverIdCode(driver.getIdCard());
                // message.setTransPriceType(area.getName());
                // message.setVehicleLicense(order.getCarNumber());
                // message.setRealVehicleLat(order.getStartLat());
                // message.setRealVehicleLon(order.getStartLng());
                message.setEncrypt(3);
                // message.setNoneMil(order.getKsMileage());
                // message.setWaitingTime(order.getWaitPrice());

                /**
                 * 经营到达
                 */
                // message.setDestVehLat(order.getEndLat());
                // message.setDestVehLon(order.getEndLng());
                // message.setOffTime(order.getFinishTime());
                // message.setPassengerMil(order.getMileage());
                // message.setPassengerTime(Double.valueOf(order.getRunTime() *
                // 60));

                /**
                 * 经营支付
                 */
                // message.setDriverName(driver.getName());
                // message.setVehicleLicense(order.getCarNumber());
                message.setBookDepTime(order.getServerTime());
                // message.setRealOnLocation(order.getStartAddress());
                // message.setOnTime(order.getCreated()); // 出发时间
                // message.setOffTime(order.getTreatmentDate());
                // message.setRealOffLocation(order.getEndAddress());
                message.setBookModel(order.getCarTypeName());
                message.setModel(order.getCarTypeName());
                // message.setPaid(order.getRealPay());
                // message.setReceivable(order.getRealPay() -
                // order.getCouponMoney().doubleValue());
                // message.setCash(order.getCashMoney().doubleValue());
                message.setLineName(order.getPayType());
                // message.setElePay(order.getSignMoney().add(order.getBalanceMoney()).add(order.getAlipayMoney()).add(order.getWeixinMoney())
                // .add(order.getUnionpayMoney()).doubleValue());
                // message.setBargain(order.getCouponMoney().doubleValue());
                // message.setExtraCharge(order.getGuoluMoney().doubleValue());
                message.setFarUpPrice(order.getYuanchengMoney().doubleValue());
                // message.setOtherExtraCharge(order.getGuoluMoney().add(order.getOtherMoney()).doubleValue());
                // message.setCalStatus("1");
                // message.setCalTime(new Date());
                // message.setBillStatus("0");
                // message.setCallCharge(order.getBudgetPay());

                SjwzMessage sjwzMessage = addSjwzMessage(driver);
                sjwzMessage.setOrderNo(order.getOrderNo());
                message.setSjwzMessage(sjwzMessage);
                if (!("CF".equals(message.getYyFlage()))) {
                    // 上车历史定位信息
                    Driver onDriver = driver;
                    onDriver.setLastLatitude(order.getStartLat());
                    onDriver.setLastLongitude(order.getStartLng());
                    SjwzMessage onSjwzMessage = addSjwzMessage(onDriver);
                    // 点击出发时间
                    onSjwzMessage.setGpsTime(order.getCreated());
                    onSjwzMessage.setOrderNo(order.getOrderNo());
                    message.setOnSjwzMessage(onSjwzMessage);
                    // 下车实时地定位信息
                    message.setOffSjwzMessage(sjwzMessage);

                }
                message.setDriCertNo(driver.getTaxiLicenseNo());
                message.setVehCertNo(car.getTaxiNo());
                message.setBrand(car.getBrand());
                message.setPassengerTel(passenger.getPhone());
                pushTemplate.sendMessage(message);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void pushTjyy(Driver driver) {
        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                TjyyMessage tjyyMessage = new TjyyMessage();

                /**
                 * BJ 统计运营信息（MOREQ_TJYY）文件内容参数
                 */
                // 司机姓名(driverName)
                tjyyMessage.setDriverName(driver.getRealname());
                // 网约车驾驶员证号（即身份证号）(driverIdCode)
                tjyyMessage.setDriverIdCode(driver.getIdCard());
                // 车型(vehicleType)如经济型、舒适型、豪华型
                // 车牌号码(vehicleLicense)
                Long carId = driver.getCarId();
                Car car = zhuancheService.findCar(carId);
                tjyyMessage.setVehicleLicense(car.getCarNumber());

                Calendar instance = Calendar.getInstance();
                Date lastTime = driverTimeService.getDriverLastOnlineTime(driver.getId(), instance);

                int status = driver.getStatus();
                if (status == 0) {
                    // 下线时间(offlineTime)
                    tjyyMessage.setOfflineTime(new Date());
                    tjyyMessage.setLoginFlag(false);
                } else {
                    // 上线时间(onlineTime)
                    tjyyMessage.setOnlineTime(lastTime);
                    tjyyMessage.setLoginFlag(true);
                }
                if (!tjyyMessage.isLoginFlag()) {
                    Map<String, Object> stringObjectMap = zhuancheService
                        .countOnDutyByDriver(driver.getId(), lastTime,
                            tjyyMessage.getOfflineTime());
                    // 总载客次数(operateSum)
                    tjyyMessage
                        .setOperateSum(((Double) stringObjectMap.get("operateSum")).intValue());
                    // 总载客次数(operateSum)
                    tjyyMessage.setPassengerMilSum(
                        new BigDecimal((Double) stringObjectMap.get("passengerMilSum")).setScale(2,
                            BigDecimal.ROUND_HALF_UP).doubleValue());
                    // 总空驶里程(noneMilSum)
                    tjyyMessage.setNoneMilSum(
                        new BigDecimal((Double) stringObjectMap.get("noneMislSum"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP)
                            .doubleValue());
                    // 总载客时间(passengerTimeSum)
                    tjyyMessage
                        .setPassengerTimeSum((Double) stringObjectMap.get("passengerTimeSum"));
                    // 总实收金额(paidSum)
                    tjyyMessage.setPaidSum(new BigDecimal((Double) stringObjectMap.get("paidSum"))
                        .setScale(2, BigDecimal.ROUND_HALF_UP)
                        .doubleValue());
                    // 总应收金额(receivableSum)
                    tjyyMessage.setReceivableSum(
                        new BigDecimal((Double) stringObjectMap.get("receivableSum"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP)
                            .doubleValue());
                    // 司机实收总金额（driverTotalIncome）
                    tjyyMessage.setDriverTotalIncome(
                        new BigDecimal((Double) stringObjectMap.get("driverTotalIncome"))
                            .setScale(2,
                                BigDecimal.ROUND_HALF_UP).doubleValue());
                    // 司机应收总金额（driverTotalReceivable）
                    tjyyMessage.setDriverTotalReceivable(
                        new BigDecimal((Double) stringObjectMap.get("driverTotalIncome"))
                            .setScale(2,
                                BigDecimal.ROUND_HALF_UP).doubleValue());
                    // 总待客里程(waitMilSum)
                    tjyyMessage.setWaitMilSum(
                        new BigDecimal((Double) stringObjectMap.get("waitMilSum"))
                            .setScale(2, BigDecimal.ROUND_HALF_UP)
                            .doubleValue());
                }

                /**
                 *
                 */
                tjyyMessage.setDriCertNo(driver.getTaxiLicenseNo());
                tjyyMessage.setVehCertNo(car.getTaxiNo());
                tjyyMessage.setLongitude(driver.getLastLongitude());
                tjyyMessage.setLatitude(driver.getLastLatitude());
                tjyyMessage.setEncrypt(3);
                SjwzMessage sjwzMessage = addSjwzMessage(driver);
                tjyyMessage.setSjwzMessage(sjwzMessage);

                // 向监管平台推送信息
                pushTemplate.sendMessage(tjyyMessage);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    /**
     * 公司基本信息（平台、服务机构、运营规模、经营许可）
     */

    @Override
    public void JgxxMessage(Company company, String basePath) {

        try {
            Setting setting = settingUtils.get();
//			basePath = setting.getWebUrl();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                JgxxMessage jgxxMessage = new JgxxMessage();

                /**
                 * BJ 1、平台备案（MOREQ_PTBA）文件内容参数：
                 */
                // 网络预约出租汽车经营许可证号
                jgxxMessage.setLicence(company.getNetAboutcarBusinessLicenseNo());
                // 经营区域 :QGHBJ全国含北京、QGBHBJ全国不含北京、BJ北京
                jgxxMessage.setServiceZone(company.getOperatingRegion());
                // 注册地行政区划代码
                jgxxMessage.setAdminCode(company.getAdministrativeDivisionNo());
                try {
                    // 法人身份证照片
                    String path = basePath + "/" + company.getLegalRepresentativePhoto();

                    File file = new File(path);
                    jgxxMessage.setLegalPhoto(IOUtils.readBase64FromInputStream(new FileInputStream(file)));
                    jgxxMessage.setLegalPhotoPath(path);
                    // 上传ftps账号图片
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }

                // 法人电话
                jgxxMessage.setLegalTel(company.getLegalRepresentativePhone());
                /**
                 * BJ 2、网约车平台公司服务所在地服务机构信息（MOREQ_JGXX）文件内容参数：
                 */
                // 网络预约出租汽车经营许可证号
                // 服务机构所在地行政区划编码
                jgxxMessage.setAgencyAdminCode(company.getServiceAgenciesNumber());
                // 服务机构名称
                jgxxMessage.setAgency(company.getServiceAgenciesName());
                // 服务机构代码
                jgxxMessage.setAgencyCode(company.getServiceAgenciesCode());
                // 服务机构具体地址
                jgxxMessage.setAgencyAddress(company.getServiceAgenciesAddress());
                // 服务机构负责人姓名
                jgxxMessage.setAgencyPeople(company.getServiceAgenciesChargePersonName());
                // 服务机构负责人联系方式
                jgxxMessage.setTel(company.getServiceAgenciesChargePersonPhone());
                // 服务机构管理人姓名
                jgxxMessage.setAgencyManagerName(company.getServiceAgenciesCustodianName());
                // 服务机构管理人联系电话
                jgxxMessage.setManagerTel(company.getServiceAgenciesCustodianPhone());
                // 行政文书送达邮寄地址
                jgxxMessage.setPostalAddress(company.getAdministrativeMailingAddress());
                // 服务机构紧急联系电话
                jgxxMessage.setAgencyEmergencyTel(company.getAgencyEmergencyTel());
                // 服务机构设立日期
                jgxxMessage.setAgencyCreateDate(company.getAgenctCreateDate());
                /**
                 * JTB 6.1.1　网约车平台公司基本信息接口
                 */
                // 公司标识
                // 公司名称
                jgxxMessage.setCompanyName(company.getCompanyName());
                // 统一社会信用代码
                jgxxMessage.setIdentifier(company.getUnifiedSocialCreditCode());
                // 注册地行政区划代码
                // 经营范围
                jgxxMessage.setBusinessScope(company.getBusinessScope());
                // 通信地址
                jgxxMessage.setContactAddress(company.getMailingAddress());
                // //经营业户经济类型
                jgxxMessage.setEconomicType(company.getEconomicTypesOfOperatingHousehold());
                // RegCapital
                jgxxMessage.setRegCapital(String.valueOf(company.getRegisteredCapital()));
                // 法人代表姓名
                jgxxMessage.setLegalName(company.getLegalRepresentative());
                // 法人代表身份证号
                jgxxMessage.setLegalID(company.getLegalRepresentativeIDCard());
                // 法人代表身份证扫描件文件编号（后置处理）
                /**
                 * JTB 6.1.2　网约车平台公司营运规模信息接口
                 */
                // 公司标识
                // 平台注册网约车辆数
                jgxxMessage.setVehicleNum(company.getRegisteredVehiclesNumber().intValue());
                // 平台注册驾驶员数
                jgxxMessage.setDriverNum(company.getRegisteredDriverNumber().intValue());
                /**
                 * JTB 6.1.4　网约车平台公司服务机构接口
                 */
                // 公司标识
                // 行政区划代码
                // 服务机构名称
                // 服务机构代码
                // 服务机构地址
                // 服务机构负责人姓名
                // 负责人联系电话
                // 服务机构管理人姓名
                // 管理人联系电话
                // 服务机构紧急联系电话
                // 行政文书送达邮寄地址
                // 服务机构设立日期
                /**
                 * JTB 6.1.5　网约车平台公司经营许可接口
                 */
                // 公司标识
                // 许可地行政区划代码
                // 网络预约出租汽车经营许可证号
                // 经营区域
                // FIXME
                // 公司名称
                // 发证机构名称
                jgxxMessage.setOrganization(company.getOperatingLicenseIssuingAgency());
                // 有效期起
                jgxxMessage.setStartDate(company.getOperatingLicenseValidityPeriodStart());
                // 有效期止
                jgxxMessage.setStopDate(company.getOperatingLicenseValidityPeriodEnd());
                // 初次发证日期
                jgxxMessage.setCertifyDate(company.getOperatingLicenseIssuingDate());

                // 向监管平台推送信息
                pushTemplate.sendMessage(jgxxMessage);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 司机备案（驾驶员基本信息、驾驶员移动终端信息）
     */
    @Override
    public void SjbaMessage(Driver driver, String basePath) {
        try {
            Setting setting = settingUtils.get();
//			basePath = setting.getWebUrl();
            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                SjbaMessage sjbaMessage = new SjbaMessage();

                sjbaMessage.setDriverName(driver.getRealname());
                sjbaMessage.setDriverIdCode(driver.getIdCard());
                sjbaMessage.setDriverTel(driver.getPhone());
                Long carId = driver.getCarId();
                Car car = zhuancheService.findCar(carId);
                sjbaMessage.setVehicleLicense(car.getCarNumber());
                int status = driver.getStatus();
                String driverStatus = (status == 0) ? "LG" : "ZG";
                sjbaMessage.setDriverStatus(driverStatus);
                // license 驾驶证扫描件. bj:扫描件照片Base64编码
                try {
                    String path = basePath + "/upload/license/" + driver.getLicense();
                    File file = new File(path);
                    sjbaMessage.setLicenceScan(IOUtils.readBase64FromInputStream(new FileInputStream(file)));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                sjbaMessage.setLicensePhotoId(driver.getLicense());
                sjbaMessage.setLicenceStartDate(driver.getDriverLicenseValid());
                sjbaMessage.setLicenceEndDate(driver.getDriverLicenseInvalid());
                sjbaMessage.setMarriage(String.valueOf(driver.getMarital()));
                sjbaMessage.setLanguageLevel(driver.getForeignLanguageAbility());
                sjbaMessage.setConStartDate(driver.getContractValid());
                sjbaMessage.setConEndDate(driver.getContractInvalid());
                sjbaMessage.setTelType(driver.getDeviceInfo());
                sjbaMessage.setTelServiceName(driver.getPhoneOperator());
                sjbaMessage.setVersion(driver.getAppVersion());
                sjbaMessage.setMapType(driver.getMapType());
                sjbaMessage.setEmergencyContact(driver.getPressingName());
                sjbaMessage.setEmergencyTel(driver.getPressingPhone());
                sjbaMessage.setEmergencyAddr(driver.getEmergencyAddress());
                String type = driver.getType();
                String fullTimeDriver = (type == "全职") ? "1" : "0";
                sjbaMessage.setFullTimeDriver(fullTimeDriver);
                sjbaMessage.setDriverCensus(driver.getDriverCensus());
                sjbaMessage.setAddress(driver.getAddressCode());
                String genderValue = driver.getGender();
                String gender = (genderValue == "男") ? "1" : "2";
                sjbaMessage.setDriverGender(gender);
                sjbaMessage.setDriverBirthday(driver.getBirthday());
                sjbaMessage.setDriverNationality(driver.getNationality());
                sjbaMessage.setDriverNation(driver.getNation());
                sjbaMessage.setDriverEducation(driver.getEducation());
                sjbaMessage.setDriverAddress(driver.getAddress());
                sjbaMessage.setDriverContactAddress(driver.getConcatAddress());
                // 驾驶员照片
                try {
                    String path = basePath + "/upload/driver/" + driver.getPhoto();
                    File file = new File(path);
                    sjbaMessage.setPhotoId(IOUtils.readBase64FromInputStream(new FileInputStream(file)));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                sjbaMessage.setDriverType(driver.getLicenseType());
                sjbaMessage.setGetDriverLicenseDate(driver.getLicenseTime());
                sjbaMessage.setTaxiDriver(driver.getCruise());
                sjbaMessage.setNetworkCarIssueOrganization(driver.getTaxiLicenseOrg());
                sjbaMessage.setNetworkCarIssueDate(DateTimeUtils.DATE_FORMAT_yyyyMMdd.parse(driver.getTaxiLicenseRecive()));
                sjbaMessage.setGetNetworkCarProofDate(DateTimeUtils.DATE_FORMAT_yyyyMMdd.parse(driver.getTaxiLicenseRecive()));
                sjbaMessage.setNetworkCarProofOn(DateTimeUtils.DATE_FORMAT_yyyyMMdd.parse(driver.getTaxiLicenseValid()));
                sjbaMessage.setNetworkCarProofOff(DateTimeUtils.DATE_FORMAT_yyyyMMdd.parse(driver.getTaxiLicenseInvalid()));
                sjbaMessage.setRegisterDate(DateTimeUtils.DATE_FORMAT_yyyyMMdd.parse(driver.getTaxiLicenseRegister()));// 这里的时间，需要从页面从头写
                boolean isInBlacklist = driver.getInBlacklist();
                int inBlacklist = (isInBlacklist) ? 1 : 0;
                sjbaMessage.setInDriverBlacklist(inBlacklist);
                sjbaMessage.setCommercialType(Integer.valueOf(
                    (driver.getCommercialType() == null) ? "1" : driver.getCommercialType()));
                sjbaMessage.setContractCompany(driver.getContractCompany());
                sjbaMessage.setCertificateNo(driver.getTaxiLicenseNo());
                sjbaMessage.setVehicleNo(car.getCarNumber());
                sjbaMessage.setFrameNo(car.getVin());
                sjbaMessage.setVehCertNo(car.getTaxiNo());
                sjbaMessage.setFlag(driver.getFlag());

                // 修改服务人员上传状态
                driverMapper.updateUpStatus(driver.getId());

                // 向监管平台推送信息
                pushTemplate.sendMessage(sjbaMessage);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 司机培训信息
     */

    @Override
    public void SjpxMessage(Train train) {
        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                SjpxMessage sjpxMessage = new SjpxMessage();

                sjpxMessage.setCourseName(train.getCourse());

                sjpxMessage.setCourseDate(DateUtils.parseDate(train.getTrainTime(), "yyyy-MM-dd"));
                sjpxMessage
                    .setCourseStartDate(DateUtils.parseDate(train.getBeginTime(), "yyyy-MM-dd"));
                sjpxMessage.setCourseEndDate(DateUtils.parseDate(train.getEndTime(), "yyyy-MM-dd"));

                sjpxMessage.setCourseDays(train.getTrainDays());
                Long driverId = train.getDriverId();
                Driver driver = driverMapper.selectByPrimaryKey(driverId);
                sjpxMessage.setLicence(driver.getTaxiLicenseNo());
                sjpxMessage.setDriverIdCode(driver.getIdCard());
                sjpxMessage.setAddress(driver.getAddressCode());
                sjpxMessage.setLicenseId(driver.getDriverLicenseId());
                sjpxMessage.setDriverName(driver.getRealname());
                // 向监管平台推送信息
                pushTemplate.sendMessage(sjpxMessage);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    /**
     * 司机信誉信息(信誉信息、统计信息)
     */

    @Override
    public void SjxxMessage(PeccancyAndComplain peccancyAndComplain) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                SjxxMessage sjxxMessage = new SjxxMessage();

                Long driverId = peccancyAndComplain.getDriverId();
                Driver driver = driverMapper.selectByPrimaryKey(driverId);
                sjxxMessage.setDriverIdCode(driver.getIdCard());
                sjxxMessage.setDriverName(driver.getRealname());
                sjxxMessage.setDriCertNo(driver.getTaxiLicenseNo());
                sjxxMessage.setLicenseId(driver.getDriverLicenseId());
                List<Order> orders = zhuancheService.queryByEmployId(driverId, "finish");
                Long completeNum = (long) orders.size();
                sjxxMessage.setCompleteNum(completeNum.intValue());
                String type1 = "违章";
                Long trafficViolationCount = peccancyAndComplainMapper.countNum(driverId, type1);
                String type2 = "投诉";
                Long complainNum = peccancyAndComplainMapper.countNum(driverId, type2);
                sjxxMessage.setTrafficViolationCount(trafficViolationCount.intValue());
                sjxxMessage.setComplainNum(complainNum.intValue());
                int peccancyNum = (int) (complainNum + trafficViolationCount);
                sjxxMessage.setPeccancyNum(peccancyNum);
                // 评分，评价算法
                if (completeNum == 0) {
                    sjxxMessage.setCreditLevel("5");
                    sjxxMessage.setBreakReason("完美");
                } else {
                    double creditLevel = ((double) peccancyNum / completeNum);
                    if (creditLevel < 0.05) {
                        sjxxMessage.setCreditLevel("5");
                        sjxxMessage.setBreakReason("完美");
                    } else if (creditLevel >= 0.05 && creditLevel < 0.1) {
                        sjxxMessage.setCreditLevel("4");
                        sjxxMessage.setBreakReason("优秀");
                    } else if (creditLevel >= 0.1 && creditLevel < 0.15) {
                        sjxxMessage.setCreditLevel("3");
                        sjxxMessage.setBreakReason("良好");
                    } else if (creditLevel >= 0.15 && creditLevel < 0.2) {
                        sjxxMessage.setCreditLevel("2");
                        sjxxMessage.setBreakReason("合格");
                    } else if (creditLevel >= 0.2) {
                        sjxxMessage.setCreditLevel("1");
                        sjxxMessage.setBreakReason("新手");
                    }
                }
                try {
                    sjxxMessage.setCheckDate(DateUtils.parseDate("2017-7-15", "yyyy-MM-dd"));
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                Long companyId = driver.getCompanyId();
                Company company = companyMapper.selectByPrimaryKey(companyId);

                sjxxMessage.setCheckAgency(company.getCompanyName());
                sjxxMessage.setAddress(Long.valueOf(driver.getAddressCode()));

                // 向监管平台推送信息
                pushTemplate.sendMessage(sjxxMessage);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    /**
     * 司机端GPS信息(驾驶员定位信息、车辆定位信息)
     */

    @Override
    public void SjwzMessage(Driver driver) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                Company company = companyMapper.selectByPrimaryKey(driver.getCompanyId());
                // 公司行政区划代码不为空
                if (!StringUtils.isBlank(company.getAdministrativeDivisionNo())) {
                    if (driver.getCarId() != null) {
                        Car car = zhuancheService.findCar(driver.getCarId());
                        if (car != null) {

                            SjwzMessage sjwzMessage = new SjwzMessage();
                            if (driver.getLastLongitude() == null
                                || driver.getLastLatitude() == null) {
                                return;
                            }
                            sjwzMessage.setLon(driver.getLastLongitude());
                            sjwzMessage.setLat(driver.getLastLatitude());
                            int status = driver.getStatus();// 0离线 1空闲 2接单
                            // 3忙碌////EMPTY空载；HALT停运；DISPATCH调度中；PASSENGER载客
                            switch (status) {
                                case 0:
                                    sjwzMessage.setOperateType("HALT");
                                    break;
                                case 1:
                                    sjwzMessage.setOperateType("EMPTY");
                                    break;
                                case 2:
                                    sjwzMessage.setOperateType("DISPATCH");
                                    break;
                                case 3:
                                    sjwzMessage.setOperateType("PASSENGER");
                                    break;

                                default:
                                    sjwzMessage.setOperateType("EMPTY");
                                    break;
                            }
                            if (status == 2 || status == 3) {
                                // 0:新单 1:已派单 /// 2:已接单 3:到达预约地 4:执行中//// 5:已完成
                                // 6:已销单
                                List<Order> orders = zhuancheService
                                    .queryByEmployId(driver.getId(), "waitorrun");
                                if (orders.size() <= 0) {
                                    sjwzMessage.setOrderNo("0");
                                    sjwzMessage.setOperateType("EMPTY");
                                } else {
                                    Order order = orders.get(0);
                                    sjwzMessage.setOrderNo(order.getOrderNo());
                                }
                            } else {
                                sjwzMessage.setOrderNo("0");
                                sjwzMessage.setOperateType("EMPTY");
                            }
                            sjwzMessage.setDriverName(driver.getRealname());
                            sjwzMessage.setDriverIdCode(driver.getIdCard());
                            sjwzMessage.setPositionType("AUTO");
                            sjwzMessage.setAzimuth(0.0);
                            sjwzMessage.setAlarmStatus("");
                            sjwzMessage.setVehicleLicense(car.getCarNumber());
                            sjwzMessage.setGpsTime(new Date());
                            sjwzMessage.setSpeed(120.0);
                            sjwzMessage.setAltitude(0.0);
                            sjwzMessage.setVehStatus("");
                            sjwzMessage.setEnCode("3");

                            sjwzMessage.setVehicleRegionCode(
                                Long.valueOf(company.getAdministrativeDivisionNo()));
                            sjwzMessage.setDriverRegionCode(company.getAdministrativeDivisionNo());
                            sjwzMessage.setMileage(driver.getDistance().longValue());
                            sjwzMessage.setDriCertNo(driver.getTaxiLicenseNo());
                            sjwzMessage.setLicenseId(driver.getTaxiLicenseNo());
                            // 向监管平台推送信息
                            pushTemplate.sendMessage(sjwzMessage);
                        }
                    }
                }
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    /**
     * 订单发票状态
     */

    @Override
    public void FpztMessage(Order order) {

        // Setting setting = settingUtils.get();
        //
        // // 判断上传开关是否开启 if (setting.isUpPlatformInfo()) {
        //
        // FpztMessage fpztMessage = new FpztMessage();
        //
        // fpztMessage.setOrderNo(order.getOrderNo());
        // fpztMessage.setBillUpdateTime(billUpdateTime);
        // fpztMessage.setVehicleLicense(order.getCarNumber()); // 向监管平台推送信息
        // pushTemplate.sendMessage(sjxxMessage); }
    }

    @Override
    public void CfxxMessage(PeccancyAndComplain peccancyAndComplain) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                CfxxMessage cfxxMessage = new CfxxMessage();

                Long driverId = peccancyAndComplain.getDriverId();
                Driver driver = driverMapper.selectByPrimaryKey(driverId);
                cfxxMessage.setDriCertNo(driver.getTaxiLicenseNo());
                cfxxMessage.setLicenseId(driver.getDriverLicenseId());

                Long carId = driver.getCarId();
                Car car = zhuancheService.findCar(carId);
                cfxxMessage.setVehicleLicense(car.getCarNumber());
                cfxxMessage.setDriverName(driver.getRealname());
                cfxxMessage.setDriverIdCode(driver.getIdCard());
                try {
                    cfxxMessage.setPunishTime(DateUtils
                        .parseDate(peccancyAndComplain.getResultTime(), "yyyy-MM-dd HH:mm:ss"));
                } catch (ParseException e) {

                    e.printStackTrace();
                }
                cfxxMessage.setPunishReason(peccancyAndComplain.getComplaintDetail());
                cfxxMessage.setPunishResult(peccancyAndComplain.getResult());
                pushTemplate.sendMessage(cfxxMessage);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void CkpjMessage(PeccancyAndComplain peccancyAndComplain) {

        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                CkpjMessage ckpjMessage = new CkpjMessage();

                ckpjMessage.setPushType(CkpjMessage.TS);

                ckpjMessage.setOrderNo(peccancyAndComplain.getOrderId());
                try {
                    ckpjMessage.setComplainTime(DateUtils
                        .parseDate(peccancyAndComplain.getComplaintTime(), "yyyy-MM-dd HH:mm:ss"));
                } catch (ParseException e) {

                    e.printStackTrace();
                }
                ckpjMessage.setComplain(peccancyAndComplain.getComplaintDetail());
                ckpjMessage.setComplainResult(peccancyAndComplain.getResult());
                pushTemplate.sendMessage(ckpjMessage);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void ClbxMessage(ClbxMessage clbxMessage) {
        try {
            Setting setting = settingUtils.get();

            if (setting.isUpPlatformInfo()) {
                pushTemplate.sendMessage(clbxMessage);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void Jszq(SettleAccountsCycle sac) {
        try {
            JszqMessage jszqMessage = new JszqMessage();
            Setting setting = settingUtils.get();

            if (setting.isUpPlatformInfo()) {
                jszqMessage.setAgency(sac.getAgency());
                jszqMessage.setAgencyType(sac.getAgencyType());
                jszqMessage.setBankAndLicence(sac.getBankAndLicence());
                jszqMessage.setBankCyclePeriod(sac.getBankCyclePeriod());
                jszqMessage.setReserveBank(sac.getReserveBank());
                jszqMessage.setBankAndLicence(sac.getBankAndLicence());
                jszqMessage.setServiceRange(sac.getServiceRange());
                jszqMessage.setPayType(sac.getPayType());

                pushTemplate.sendMessage(jszqMessage);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void ClbaMessage(Car car, String basePath) {

        try {
            Setting setting = settingUtils.get();
//			basePath = setting.getWebUrl();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                ClbaMessage clba = new ClbaMessage();

                // A.4.7. 车辆基本信息接口begin
                // CompanyId:公司标识
                // Address:车辆所在城市（注册地行政区划代码）,数字型(area查询语句)
                Long companyId = car.getCompanyId();
                Company company = companyMapper.selectByPrimaryKey(companyId);
                clba.setAddress(company.getAdministrativeDivisionNo());
                // VehicleNo:车辆号牌
                clba.setVehicleLicense(car.getCarNumber());
                // PlateColor:车牌颜色
                clba.setBoardColor(car.getPlateColor());
                // Seats:核定载客位;数字型
                clba.setSeats(Integer.valueOf(car.getPermitted()));
                // Brand:车辆厂牌
                clba.setBrand(car.getBrand());
                // Model:车辆型号
                clba.setVehicleBrand(car.getVehicleModel());
                // VehicleType:车辆类型,以机动车行驶证为准
                clba.setVehicleType(car.getVehicleType());
                // OwnerName:车辆所有人
                clba.setDriverProType(car.getOwner());
                // VehicleColor:车身颜色
                clba.setVehicleColor(car.getBodyColor());
                // 车辆照片

                try {
                    String path = basePath + "/" + car.getPicture();
                    File file = new File(path);
                    clba.setVehiclePhoto(IOUtils.readBase64FromInputStream(new FileInputStream(file)));
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
                // EngineId:发动机号
                clba.setEngineId(car.getEngineNo());
                // VIN:车辆VIN码
                clba.setVin(car.getVin());
                // CertifyDateA:车辆注册日期,数字型,F8,车辆购买日期
                clba.setVehRegisDate(car.getRegistrationTime());
                // FuelType:车辆燃料类型
                clba.setFuelType(car.getFuel());
                // EngineDisplace:发动机排量
                clba.setEngineDisplace(car.getDisplacement());
                // Certificate:运输证字号
                clba.setCertificateNo(car.getTaxiNo());
                // TransAgency:车辆运输证发证机构
                clba.setTransAgency(car.getTaxiAgency());
                // TransArea:车辆经营区域
                clba.setTransArea(company.getCityName());
                // TransDateStart:车辆运输证有效期起,数字型,YYYYMMDD
                clba.setTransDateStart(car.getValidTime());
                // TransDateStop:车辆运输证有效期止,数字型,YYYYMMDD
                clba.setTransDateStop(car.getInvalidTime());
                // CertifyDateB:车辆初次登记日期,数字型,YYYYMMDD
                clba.setNcpFirstDate(car.getTaxiRegisterTime());
                // FixState:车辆检修状态,字符型,0：未检修1：已检修2：未知
                clba.setExamStatus(String.valueOf(car.getMaintenanceStatus()));
                // 车辆下次年检时间
                clba.setNextExamDate(car.getOverhaulTime());
                // CheckState:车辆年度审验状态
                clba.setCheckState("" + car.getInspectioStatus());
                // ncpDeviceSerialNum:网约车发票打印设备序列号
                clba.setNcpDeviceSerialNum(car.getDeviceSerial());
                // GPSBrand:卫星定位装置品牌
                clba.setGpsBrand(car.getDeviceBrand());
                // GPSModel:卫星定位装置型号
                clba.setGpsDeviceType(car.getDeviceModel());
                // GPSInstallDate:卫星定位设备安装日期,数字型,YYYYMMDD
                clba.setGpsFixDate(car.getDeviceInstallTime());
                // RegisterDate:报备日期,数字型,YYYYMMDD
                clba.setRegisterDate(car.getBuyTime());
                // CommercialType:服务类型,数字型,：网络预约出租2：巡游出租车3：私人小客车合乘
                clba.setCommercialType(car.getCommercialType());
                // FareType:运价类型编码,字符型
                Long carTypeId = car.getCarTypeId();
                com.ybkj.daijia.server.zhuan.ServiceType serviceType = zhuancheService
                    .queryServiceType(carTypeId, companyId,
                        ServiceType.tangzu.toString());
                clba.setTransPriceType(serviceType.getAreaName());
                // State:状态,数字型,0：有效1：失效
                //Flag:操作标识,1：新增2：更新3：删除
                clba.setFlag(car.getFlag());
                // UpdateTime:更新时间,
                // A.4.7. 车辆基本信息接口end
                clba.setDistanceTotal(car.getTotalMileage());

                // 修改车辆上传状态
                zhuancheService.updateUpStatus(car.getId());

                pushTemplate.sendMessage(clba);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }

    }

    @Override
    public void CkpjMessage(CkpjMessage ckpjMessage) {
        try {
            Setting setting = settingUtils.get();
            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                pushTemplate.sendMessage(ckpjMessage);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void CkbaMessage(CkbaMessage ckbaMessage, Passenger passenger) {
        try {
            Setting setting = settingUtils.get();
            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                pushTemplate.sendMessage(ckbaMessage);
                // 修改乘客上传状态
                passenger.setUpStatus(1);
                memberService.updatePassenger(passenger);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void YjxxMessage(FeeScale feeScale) {
        try {
            Setting setting = settingUtils.get();
            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                Company company = companyMapper.selectMainCompany();

                YjxxMessage yjxxMessage = new YjxxMessage();

                /**
                 * BJ 3、运价信息（MOREQ_YJXX）文件内容参数：
                 */
                // 网络预约出租汽车经营许可证号
                yjxxMessage.setLicence(company.getNetAboutcarBusinessLicenseNo());
                // 行政区划编号
                yjxxMessage.setAdminCode(company.getAdministrativeDivisionNo());
                // 运价类型
                yjxxMessage.setTransPriceType(feeScale.getFareType());
                // 运价类型说明
                yjxxMessage.setTransPriceNote(feeScale.getFareTypeNote());
                // 运价有效期起
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Date fareValidOn = sdf.parse(feeScale.getFareValidOn());
                yjxxMessage.setTransValidStart(fareValidOn);
                // 运价有效期止
                Date fareValidOff = sdf.parse(feeScale.getFareValidOff());
                yjxxMessage.setTransValidEnd(fareValidOff);
                // 起步价
                yjxxMessage.setStartPrice(feeScale.getStartFare().doubleValue());
                // 起步时长
                yjxxMessage.setStartTimer(feeScale.getStartMinute());
                // 起步里程
                yjxxMessage.setStartMile(feeScale.getStartMile());
                // 计程单价 （按公里）
                yjxxMessage.setPricePerMile(feeScale.getUnitPricePerMile().doubleValue());
                // 计时单价（按分钟）
                yjxxMessage.setPricePerTimer(feeScale.getUnitPricePerMinute().doubleValue());
                // 低速计时单价（按分钟）
                yjxxMessage.setPriceLowSpeed(feeScale.getLowSpeedPricePerMinute().doubleValue());
                // 单程加价单价
                yjxxMessage.setSingleAddPrice(feeScale.getSingleUnitPrice().doubleValue());
                // 单程加价公里
                yjxxMessage.setSingleAddMile(feeScale.getSinglePriceStartMile());
                // 是否有效
                // 车辆类型
                yjxxMessage.setVehicleType(feeScale.getVehicleType());
                // 营运早高峰起时间
                yjxxMessage
                    .setOperMorningStartTime(String.valueOf(feeScale.getMorningPeakTimeOn()));
                // 营运早高峰止时间
                yjxxMessage.setOperMorningEndTime(String.valueOf(feeScale.getMorningPeakTimeOff()));
                // 营运晚高峰起时间
                yjxxMessage.setNightTimeStart(String.valueOf(feeScale.getNightTimeStart()));
                // 营运晚高峰止时间
                yjxxMessage.setNightTimeEnd(String.valueOf(feeScale.getNightTimeEnd()));
                // 其他营运高峰起时间
                yjxxMessage.setOtherPeakStartTime(String.valueOf(feeScale.getOtherPeakTimeOn()));
                // 其他营运高峰止时间
                yjxxMessage.setOtherPeakEndTime(String.valueOf(feeScale.getOtherPeakTimeOff()));
                // 高峰时间单程加价单价
                yjxxMessage.setPeakSingleAddPrice(feeScale.getPeakUnitPrice().doubleValue());
                // 高峰时间单程加价公里
                yjxxMessage.setPeakSingleAddMile(feeScale.getPeakPriceStartMile());
                // 夜间公里单价
                yjxxMessage.setNightFeeMile(feeScale.getNightPricePerMile().doubleValue());
                // 夜间时间单价
                yjxxMessage.setNightFeeTime(feeScale.getNightPricePerMinute().doubleValue());
                // 其他加价金额
                yjxxMessage.setOtherAddPrice(feeScale.getOtherPrice().doubleValue());
                // 最低消费
                yjxxMessage.setMinPrice(feeScale.getMinPrice().doubleValue());
                // 夜间起时间
                yjxxMessage.setOperNightStartTime(String.valueOf(feeScale.getEveningPeakTimeOn()));
                // 夜间止时间
                yjxxMessage.setOperNightEndTime(String.valueOf(feeScale.getEveningPeakTimeOff()));

                //修改上传标识
                feeScale.setUpStatus(1);
                feeScaleService.updateById(feeScale);

                pushTemplate.sendMessage(yjxxMessage);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Override
    public void shenzhenTimer(ShenZhenTimer shenzhenTimer) {

        try {
            Setting setting = settingUtils.get();

            if (setting.isUpPlatformInfo()) {

                pushTemplate.sendMessage(shenzhenTimer);
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void CkblMessage(Passenger passenger, String string) {
        try {
            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                CkblMessage ckblMessage = new CkblMessage();

                ckblMessage.setBlackTime(new Date());
                ckblMessage.setStatus(1);
                ckblMessage.setIdentityNumber(passenger.getIdcard());
                ckblMessage.setPassengerName(passenger.getName());
                ckblMessage.setPassengerTel(passenger.getPhone());
                ckblMessage.setReason("违反用户协议");
                pushTemplate.sendMessage(ckblMessage);

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private SjwzMessage addSjwzMessage(Driver driver) {

        try {

            if (driver.getCarId() != null) {
                Car car = zhuancheService.findCar(driver.getCarId());
                if (car != null) {
                    SjwzMessage sjwzMessage = new SjwzMessage();
                    if (driver.getLastLongitude() == null || driver.getLastLatitude() == null) {
                        return null;
                    }
                    sjwzMessage.setLon(driver.getLastLongitude());
                    sjwzMessage.setLat(driver.getLastLatitude());
                    // 0离线 1空闲 2接单
                    int status = driver.getStatus();
                    // 3忙碌////EMPTY空载；HALT停运；DISPATCH调度中；PASSENGER载客
                    switch (status) {
                        case 0:
                            sjwzMessage.setOperateType("HALT");
                            break;
                        case 1:
                            sjwzMessage.setOperateType("EMPTY");
                            break;
                        case 2:
                            sjwzMessage.setOperateType("DISPATCH");
                            break;
                        case 3:
                            sjwzMessage.setOperateType("PASSENGER");
                            break;

                        default:
                            sjwzMessage.setOperateType("EMPTY");
                            break;
                    }
                    if (status == 2 || status == 3) {
                        // 0:新单 1:已派单 /// 2:已接单 3:到达预约地 4:执行中//// 5:已完成 6:已销单
                        List<Order> orders = zhuancheService
                            .queryByEmployId(driver.getId(), "waitorrun");
                        if (orders.size() <= 0) {
                            sjwzMessage.setOrderNo("0");
                            sjwzMessage.setOperateType("EMPTY");
                        } else {
                            Order order = orders.get(0);
                            sjwzMessage.setOrderNo(order.getOrderNo());
                        }
                    } else {
                        sjwzMessage.setOrderNo("0");
                        sjwzMessage.setOperateType("EMPTY");
                    }
                    sjwzMessage.setDriverName(driver.getRealname());
                    sjwzMessage.setDriverIdCode(driver.getIdCard());
                    sjwzMessage.setPositionType("AUTO");
                    sjwzMessage.setAzimuth(0.0);
                    sjwzMessage.setAlarmStatus("");
                    sjwzMessage.setVehicleLicense(car.getCarNumber());
                    sjwzMessage.setGpsTime(new Date());
                    sjwzMessage.setSpeed(120.0);
                    sjwzMessage.setAltitude(0.0);
                    sjwzMessage.setVehStatus("");
                    sjwzMessage.setEnCode("3");
                    Company company = companyMapper.selectByPrimaryKey(driver.getCompanyId());
                    sjwzMessage
                        .setVehicleRegionCode(Long.valueOf(company.getAdministrativeDivisionNo()));
                    sjwzMessage.setDriverRegionCode(company.getAdministrativeDivisionNo());
                    sjwzMessage.setMileage(driver.getDistance().longValue());
                    sjwzMessage.setDriCertNo(driver.getTaxiLicenseNo());
                    sjwzMessage.setLicenseId(driver.getTaxiLicenseNo());

                    return sjwzMessage;
                }
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
        return null;
    }

    @Override
    public void ddbc(Order order) {

        try {

            Setting setting = settingUtils.get();

            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {

                DdbcMessage ddbcMessage = new DdbcMessage();

                try {
                    // 订单号(orderNo)
                    ddbcMessage.setOrderNo(order.getOrderNo());
                    // 订单状态(orderType)
                    // 乘客称谓(passengerName)
                    Passenger passenger = memberService.findOnePassenger(order.getPassengerId());
                    ddbcMessage.setPassengerName(passenger.getName());
                    // 乘客性别(passengerGender)
                    ddbcMessage
                        .setPassengerGender((passenger.getGender() == 0) ? "MALE" : "FEMALE");
                    // 乘客电话(passengerTel)
                    ddbcMessage.setPassengerTel(passenger.getPhone());
                    // 用车地点(useLocale)
                    ddbcMessage.setUseLocale(order.getStartAddress());
                    // 用车地点经度(useLon)
                    ddbcMessage.setUseLon(order.getStartLng());
                    // 用车地点纬度(useLat)
                    ddbcMessage.setUseLat(order.getStartLat());
                    // 用车时间(useTime)
                    ddbcMessage.setUseTime(order.getCreated());
                    // 订单时间(orderTime)
                    ddbcMessage.setOrderTime(order.getCreated());
                    // 目的地(destination)
                    ddbcMessage.setDestination(order.getEndAddress());
                    // 目的地经度(destLon)
                    ddbcMessage.setDestLon(order.getEndLng());
                    // 目的地纬度(destLat)
                    ddbcMessage.setDestLat(order.getEndLat());
                    // 乘客备注(passengerDemand)
                    ddbcMessage.setPassengerDemand(
                        (StringUtils.isBlank(order.getOrderMemo())) ? "" : order.getOrderMemo());
                    // 是否是语音订单（isVoice）
                    ddbcMessage.setIsVoice("N");
                    // 语音地址（voiceUrl）
                    ddbcMessage.setVoiceUrl("");
                    // 乘客身份证号
                    // 乘客类型（passengerType）
                    ddbcMessage.setPassengerType("GP");
                    // 派单时间（dispatchTime）
                    List<OrderStatus> statusList = order.getStatusList();
                    for (OrderStatus orderStatus : statusList) {
                        if (orderStatus.getStatus() == 1) {
                            ddbcMessage.setDispatchTime(orderStatus.getCreated());
                        }
                    }
                    // 订单类型(bespeakType)
                    ddbcMessage.setBespeakType("IMMEDIATE");
                    // 上车地点行政区划编号（adminCode）
                    // 司机姓名(driverName)
                    Car car = zhuancheService.findCar(order.getCarId());
                    Long driverId = car.getEmployId();
                    Driver driver = driverMapper.selectByPrimaryKey(driverId);
                    ddbcMessage.setDriverName(driver.getRealname());
                    // 网约车驾驶员证号(driverIdCode)
                    ddbcMessage.setDriverIdCode(driver.getIdCard());
                    // 司机电话(driverTel)
                    ddbcMessage.setDriverTel(driver.getPhone());
                    // 车牌号码(vehicleLicense)
                    ddbcMessage.setVehicleLicense(car.getCarNumber());
                    // 派单车辆经度(vehicleLon)
                    ddbcMessage.setVehicleLon(order.getStartLng());
                    // 派单车辆纬度(vehicleLat)
                    ddbcMessage.setVehicleLat(order.getStartLat());
                    // 车辆实际出发地点经度 (realVehicleLon)
                    ddbcMessage.setRealVehicleLon(order.getRealStartLng());// 车辆实际出发地点经度
                    // 车辆实际出发地点纬度 (realVehicleLat)
                    ddbcMessage.setRealVehicleLat(order.getRealStartLat());// 车辆实际出发地点纬度
                    // 实际上车地点 (realOnLocation)
                    ddbcMessage.setRealOnLocation(order.getRealStartAddress());// 实际上车地点
                    // 实际下车地点 (realOffLocation)
                    ddbcMessage.setRealOffLocation(order.getEndAddress());// 实际下车地点
                    // 完成时车辆经度(destVehLon)
                    ddbcMessage.setDestVehLon(order.getEndLng());
                    // 完成时车辆纬度(destVehLat)
                    ddbcMessage.setDestVehLat(order.getEndLat());
                    // 上车时间(onTime)
                    for (OrderStatus orderStatus : statusList) {
                        if (orderStatus.getStatus() == 4) {
                            ddbcMessage.setOnTime(orderStatus.getCreated());
                        }
                    }
                    // 下车时间(offTime)
                    for (OrderStatus orderStatus : statusList) {
                        if (orderStatus.getStatus() == 5) {
                            ddbcMessage.setOffTime(orderStatus.getCreated());
                            // 结算时间(calTime)
                            ddbcMessage.setCalTime(orderStatus.getCreated());
                        }
                    }
                    // 空驶里程(noneMil)
                    ddbcMessage.setNoneMil(0.0);
                    // 待客里程（waitMil）
                    ddbcMessage.setWaitMil(0.0);
                    // 载客里程(passengerMil)
                    ddbcMessage.setPassengerMil(order.getMileage());
                    // 载客时间(passengerTime)
                    ddbcMessage.setPassengerTime(order.getRunTime().doubleValue());
                    // 低速时长 (lowSpeedTime)
                    ddbcMessage.setLowSpeedTime(0.0);
                    // 等候时间(waitingTime)
                    ddbcMessage.setWaitingTime(0.0);
                    // 现金支付金额(cash)
                    ddbcMessage.setCash(order.getCashMoney().doubleValue());
                    // 电子支付金额(elePay)
                    ddbcMessage.setElePay(
                        order.getAlipayMoney().doubleValue() + order.getWeixinMoney().doubleValue()
                            + order.getSignMoney().doubleValue() + order.getBalanceMoney()
                            .doubleValue());
                    // Pos机支付金额(posPay)
                    ddbcMessage.setPosPay(0.0);
                    // 实收金额(paid)
                    ddbcMessage.setPaid(order.getRealPay());
                    // 应收金额(receivable)
                    ddbcMessage.setReceivable(
                        order.getRealPay().doubleValue() + order.getCouponMoney().doubleValue());
                    // 优惠金额(bargain)
                    ddbcMessage.setBargain(order.getCouponMoney().doubleValue());
                    // 电召费/预约服务费(callCharge)
                    ddbcMessage.setCallCharge(0.0);
                    // 等候费用(waitingCharge)
                    ddbcMessage.setWaitingCharge(order.getWaitPrice());
                    // 附加费(extraCharge)
                    ddbcMessage.setExtraCharge(
                        order.getGuoluMoney().doubleValue() + order.getYuanchengMoney()
                            .doubleValue()
                            + order.getYuanchengMoney().doubleValue());
                    // 其他附加费用(otherExtraCharge)
                    ddbcMessage.setOtherExtraCharge(order.getOtherMoney().doubleValue());
                    // 高峰时段时间加价金额(rushAddCharge)
                    ddbcMessage.setRushAddCharge(0.0);
                    // 夜间时段里程加价金额(nightAddCharge)
                    ddbcMessage.setNightAddCharge(0.0);
                    // 动态加价金额(dynamicsAddCharge)
                    ddbcMessage.setDynamicsAddCharge(0.0);
                    // 特殊情况加价倍数（specialTimes）
                    ddbcMessage.setSpecialTimes(0.0);
                    // 特殊情况加价倍数说明（specialTimesNote）
                    ddbcMessage.setSpecialTimesNote("");
                    // 司机实收金额（driverIncome）
                    ddbcMessage.setDriverIncome(
                        order.getEmployProfit() == null ? 0.00 : order.getEmployProfit());
                    // 司机应收金额（driverReceivable）
                    ddbcMessage.setDriverReceivable(
                        order.getRealPay() == null ? 0.00 : order.getRealPay());
                    // 运价类型 (transPriceType)
                    Area area = areaService.findOne(order.getAreaId());
                    if (null != area) {
                        ddbcMessage.setTransPriceType(area.getName());
                    }
                    // Pos机收单机构(posAgency)
                    ddbcMessage.setPosAgency("");
                    // 电子支付机构(ePay)
                    ddbcMessage.setePay("支付宝");
                    // 结算状态(calStatus)
                    ddbcMessage.setCalStatus("1");
                    // 发票状态(billStatus)
                    /**
                     *
                     */
                    ddbcMessage.setOrderStatus("DDWC");
                    ddbcMessage.setEncrypt("3");
                    ddbcMessage.setTransPriceType(area.getName());
                    ddbcMessage.setCancelTime("");
                    ddbcMessage.setOperator("");
                    ddbcMessage.setCancelTypeCode("");
                    ddbcMessage.setCancelReason("");
                    ddbcMessage.setVehCertNo(car.getTaxiNo());
                    ddbcMessage.setDriCertNo(driver.getTaxiLicenseNo());
                    ddbcMessage.setDispatchTime(order.getCreated());
                    SjwzMessage sjwzMessage = new SjwzMessage();
                    sjwzMessage.setDriCertNo(driver.getTaxiLicenseNo());
                    sjwzMessage.setLicenseId(driver.getDriverLicenseId());
                    sjwzMessage.setGpsTime(order.getCreated());
                    sjwzMessage.setLon(order.getStartLng());
                    sjwzMessage.setLat(order.getStartLat());
                    sjwzMessage.setEnCode("3");
                    sjwzMessage.setAzimuth(0.0);
                    sjwzMessage.setAltitude(0.0);
                    sjwzMessage.setSpeed(90.0);
                    sjwzMessage.setOperateType("2");
                    sjwzMessage.setPositionType("DDJD");
                    sjwzMessage.setOrderNo(order.getOrderNo());
                    ddbcMessage.setSjwzMessage(sjwzMessage);
                    // 推送信息
                    pushTemplate.sendMessage(ddbcMessage);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    @Override
    public void vpnLive(Company company) {
        try {
            Setting setting = settingUtils.get();
            // 判断上传开关是否开启
            if (setting.isUpPlatformInfo()) {
                JgxxMessage jgxxMessage = new JgxxMessage();
                /**
                 * JTB 6.1.2　网约车平台公司营运规模信息接口
                 */
                // 公司标识
                // 平台注册网约车辆数
                jgxxMessage.setVehicleNum(company.getRegisteredVehiclesNumber().intValue());
                // 平台注册驾驶员数
                jgxxMessage.setDriverNum(company.getRegisteredDriverNumber().intValue());
                // vpn活性标识
                jgxxMessage.setConnectFlage("connectFlage");
                // 向监管平台推送信息
                pushTemplate.sendMessage(jgxxMessage);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
